package com.zto.mybatis.custom2.session;

import com.zto.mybatis.custom2.config.MapperRegistory;
import com.zto.mybatis.custom2.config.MyConfiguration;
import com.zto.mybatis.custom2.executor.Executor;
import com.zto.mybatis.custom2.proxy.MapperProxy;

import java.lang.reflect.Proxy;

/**
 * Created by xingyuchao on 2017-07-09.
 */
public class MySqlSession {

    private MyConfiguration configuration;

    private Executor executor;

    public MyConfiguration getConfiguration(){
        return configuration;
    }

    public MySqlSession(MyConfiguration configuration, Executor executor) {
        this.configuration = configuration;
        this.executor = executor;
    }

    public <T> T getMapper(Class<T> clazz) {
        return (T) Proxy.newProxyInstance(clazz.getClassLoader(),
                new Class[]{clazz},new MapperProxy(this,clazz));
    }

    public <T> T selectOne(MapperRegistory.MapperData mapperData, Object parameter) throws Exception {
        return executor.query(mapperData, parameter);
    }


}
